package com.example.final_project.ShoppingCar.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.final_project.R;
import com.example.final_project.Usr.entry.UserStore;

import java.util.ArrayList;
import java.util.List;

public class ShoppingCarAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<UserStore> userStores;
    private ImageView imageView;
    private TextView price,name;

    public ShoppingCarAdapter(List<UserStore> list,Context context){
        this.userStores = list;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder holder = null;
        View view = LayoutInflater.from(context).inflate(R.layout.shoppingcar_tag,parent,false);
        holder = new StoreTagHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        StoreTagHolder storeTagHolder = (StoreTagHolder) holder;
        storeTagHolder.setData(position);
    }

    @Override
    public int getItemCount() {
        return userStores.size();
    }

    class StoreTagHolder extends RecyclerView.ViewHolder {
        public StoreTagHolder(@NonNull View itemView) {
            super(itemView);
        }

        public void setData(int position){
            UserStore userStore = userStores.get(position);
            imageView = itemView.findViewById(R.id.shoppingtag_img);
            name = itemView.findViewById(R.id.shoppingtag_name);
            price = itemView.findViewById(R.id.shoppingtag_price);
            Glide.with(context).load("http://10.150.11.9:8086/chengcar/banners/"+userStore.getImg()).into(imageView);
            name.setText(userStore.getName());
            price.setText(userStore.getPrice());
        }

    }

}
